Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _api = _interopRequireDefault(require("../../utils/api")), _util = _interopRequireDefault(require("../../utils/util")), _cardUtil = _interopRequireDefault(require("../../utils/card-util")), _radarUtil = require("../../utils/radar-util");

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var LISTEN = 1, _default = {
    observerCard: function() {
        var i = this, t = this.$appData.NAVBAR_TOTAL_HEIGHT;
        wx.lazyFetch({
            selector: "#cardBox",
            disconnect: !1,
            margins: {
                top: -t
            },
            handler: function(t) {
                var a = t.intersectionRatio, e = t.boundingClientRect;
                i.setData({
                    isSticky: !a && e.top < 200
                });
            }
        });
    },
    cardCodeShown: function() {
        var t = this.data.card, a = this.selectComponent("#viewer"), e = _cardUtil.default.getShareCardUrl(t);
        a.set(e), a.show();
    },
    getAudioContent: function() {
        var t = this;
        this.audioContext || (this.audioContext = wx.createInnerAudioContext(), this.audioContext.onPlay(function() {
            t.radarPush(_radarUtil.RADAR_TYPES.VOICE), console.log("开始播放");
        }), this.audioContext.onStop(function() {
            t.stopAudio(), console.log("停止播放");
        }), this.audioContext.onEnded(function() {
            t.setData({
                playing: !1
            }), console.log("自然停止播放");
        }));
        var a = this.data.card.signvoice;
        return a && (this.audioContext.src = a.url), this.audioContext;
    },
    playAudio: function() {
        this.createRecond(), this.setData({
            playing: !0
        }), this.$report("card_play_voice"), this.getAudioContent().play();
    },
    createRecond: function() {
        var t = this, a = this.data.card.signvoice;
        a.islisten || _api.default.minicard.card.createvoicesignrecord({
            data: {
                id: a.id
            }
        }).then(function() {
            t.setData({
                "card.signvoice.islisten": LISTEN
            });
        });
    },
    onHide: function() {
        this.stopAudio();
    },
    stopAudio: function() {
        this.audioContext && (this.setData({
            playing: !1
        }), this.getAudioContent().stop());
    },
    getCardData: function() {
        var t = this.data, a = t.card, e = t.transferList;
        return +a.grade === _cardUtil.default.GRADE.DISMISSION ? e.filter(function(t) {
            return +t.grade !== _cardUtil.default.GRADE.DISMISSION;
        })[0] : a;
    },
    call: function() {
        this.radarPush(_radarUtil.RADAR_TYPES.CALL), this.$report("card_view_tap_call"), 
        _cardUtil.default.callCardMobile(this.getCardData());
    },
    showAvatar: function() {
        _cardUtil.default.showAvatar(this.getCardData());
    },
    showQrcode: function() {
        this.$report("card_view_tap_showqrcode"), _cardUtil.default.showQrcode(this.getCardData());
    },
    showWxQrcode: function() {
        var t = this, a = this.getCardData();
        this.$report("card_view_tap_wxqrcode"), a.wxQrcode ? _util.default.savePhotoToAlbum(a.wxQrcode).then(function() {
            return t.$route("/pages/view/view?type=wechat&save=1&value=".concat(encodeURIComponent(a.wxQrcode)));
        }) : this.fillWechat();
    },
    showAddressMap: function() {
        var t = this.data.card;
        t.addresslat && t.addresslng ? (this.radarPush(_radarUtil.RADAR_TYPES.ADDRESS), 
        _cardUtil.default.openLocation(t)) : (this.$put("card.data", Object.assign({}, t)), 
        this.$route("/pages/card/address/address"));
    },
    copyInfo: function(t) {
        var a = this, e = t.currentTarget.dataset.name, i = {
            formattedMobile: function() {
                return a.call();
            },
            addressdetail: function() {
                return a.showAddressMap();
            },
            email: function(t) {
                a.clipData(t), a.radarPush(_radarUtil.RADAR_TYPES.COPYEMAIL);
            },
            wechat: function(t) {
                a.clipData(t), a.$report("card_view_tap_wechat"), a.radarPush(_radarUtil.RADAR_TYPES.COPYWECHAT);
            },
            wxQrcode: function() {
                return a.showWxQrcode();
            },
            mycode: function() {
                return a.cardCodeShare();
            }
        };
        i[e] && i[e](e);
    },
    clipData: function(t) {
        var a = this.data.card, e = a && a[t];
        if (e) wx.fPromise("setClipboardData", {
            data: e
        }).then(function() {
            "wechat" === t ? (wx.hideToast(), wx.showModal({
                title: "微信号已复制",
                content: "Ta的微信号(".concat(e, ")已复制，微信中长按粘贴即可申请加为好友"),
                showCancel: !1
            })) : wx.showToast({
                title: "复制成功",
                duration: 500
            });
        }); else switch (t) {
          case "wechat":
            this.fillWechat();
            break;

          case "email":
            this.$put("card.data", {
                name: t,
                value: "",
                data: {
                    cardid: a.cardid
                }
            }), this.$route("/pages/card/other/other");
        }
    },
    fillWechat: function() {
        var t = this.data.card;
        this.$put("card.data", {
            name: "wechat",
            value: t.wechat,
            data: {
                wxQrcode: t.wxQrcode,
                cardid: t.cardid
            }
        }), this.$route("/pages/card/other/other");
    },
    radarPush: function(t, a) {
        (0, _radarUtil.radarPush)(this.data.card, t, a);
    }
};

exports.default = _default;